/*Elise Eiden
Taryn Green
Kevin McGinn 

Software Engineering
Network Feasibility Test

Referencing the Boost Daytime example*/

#include <iostream>
#include <cstdlib>
#include <boost/array.hpp>
#include <boost/asio.hpp>

using boost::asio::ip::udp;

int main(int argc, char* argv[]) {
	try {
		if (argc != 3) {
			std::cerr << "Enter a host and sequence of directional instructions." << std::endl;
			exit(1);
		}

	// Create io service
	boost::asio::io_service io_service;

	// Create a resolver to find the correct remote endpoint
	udp::resolver resolver(io_service);
	udp::resolver::query query(udp::v4(),"localhost","3322");//argv[1], "daytime");		//Error here
	udp::endpoint receiver_endpoint = *resolver.resolve(query);	//Fails here

	// Establish a socket for sending data
	udp::socket socket(io_service);
	// Initiate contact with the endpoint
	socket.open(udp::v4());

	// Establish a sending buffer
	boost::array<char, 1> send_buffer = { {0} };
	//add to sending buffer
	int i = 0;
	while(argv[2][i] != NULL) {
	  send_buffer[i] = argv[2][i];
	  i++;
	}

	socket.send_to(boost::asio::buffer(send_buffer), receiver_endpoint);

	// Prepare to accept whatever server sends back
	boost::array<char, 128> receiver_buffer;

	udp::endpoint sender_endpoint;
	std::cout << "Line 62\n";
//	size_t len = socket.receive_from(boost::asio::buffer(receiver_buffer,1000), sender_endpoint);	//Error here, 1000 added as attempt
	std::cout << "Line 64\n";
//	std::cout.write(receiver_buffer.data(), len);
	std::cout << "Line 66\n";

	}

	// Handle exceptions
	catch (std::exception& e) {
		std::cerr << e.what() << std::endl;
	}
	return 0;
}
